package com.peng.mybatis.reflection.property;

public class PropertyNamer {

    private PropertyNamer() {
    }

    /**
     * 将标准方法名变为属性名
     */
    public static String methodToProperty(String name) {
        if (name.startsWith("is")) {
            name = name.substring(2);
        } else if (name.startsWith("get") || name.startsWith("set")) {
            name = name.substring(3);
        } else {
            throw new IllegalArgumentException("无法解析的方法名" + name);
        }
        return name.substring(0, 1).toLowerCase() + name.substring(1);
    }

    /**
     * 是否基本方法
     */
    public static boolean isProperty(String name) {
        return name.startsWith("is") || name.startsWith("get") || name.startsWith("set");
    }

    public static boolean isGetter(String name) {
        return name.startsWith("get") || name.startsWith("is");
    }

    public static boolean isSetter(String name) {
        return name.startsWith("get") || name.startsWith("set");
    }

}
